package com.neulogistics.contrib.warehouse.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.contrib.warehouse.api.application.viewmodel.CirculationOrderViewModel;
import com.neulogistics.contrib.warehouse.domain.model.valueobject.GoodsItem;
import com.neulogistics.contrib.warehouse.infrastructure.persistence.orm.po.CirculationOrderPO;
import org.springframework.beans.BeanUtils;

public class CirculationOrderPOVMConverter {
    public static CirculationOrderViewModel POToVM(CirculationOrderPO po){
        if(po == null)
            return null;

        CirculationOrderViewModel viewModel = new CirculationOrderViewModel();
        BeanUtils.copyProperties(po, viewModel);
        // long转string
        viewModel.setCirculationId(po.getCirculationId().toString());
        if(po.getTaskId() != null){
            viewModel.setTaskId(po.getTaskId().toString());
        }
        if(po.getTaskId() != null){
            viewModel.setTransferId(po.getTransferId().toString());
        }

        // 货物对象转换
        viewModel.setGoodsItems(JSONUtil.toList(po.getGoodsItems(), GoodsItem.class));

        return viewModel;
    }
}
